<p>This rule flags code that uses <code>JSON.parse(JSON.stringify())</code> or library functions like <code>_.cloneDeep()</code> to create deep clones
of objects.</p>
<h2>Why is this an issue?</h2>
<p><code>structuredClone()</code> is the modern, standardized way to create deep clones in JavaScript. It’s part of the web platform and provides
several advantages over alternative approaches.</p>
<p>The <code>JSON.parse(JSON.stringify())</code> pattern has significant limitations. It cannot handle functions, undefined values, symbols, or Date
objects correctly. It also fails with circular references and loses prototype information.</p>
<p>Library-based solutions like <code>_.cloneDeep()</code> work correctly but add external dependencies to your project. They increase bundle size and
create maintenance overhead.</p>
<p><code>structuredClone()</code> handles these cases properly. It supports a wide range of data types including Date objects, RegExp, Maps, Sets, and
even handles circular references. It’s also faster than JSON-based approaches and doesn’t require external libraries.</p>
<h3>What is the potential impact?</h3>
<p>Using inferior cloning methods can lead to subtle bugs when the cloned objects don’t behave as expected. The JSON approach can silently corrupt
data by dropping properties or changing types. External libraries increase bundle size and create dependency management overhead.</p>
<h3>How to fix?</h3>
<p>Replace <code>JSON.parse(JSON.stringify())</code> with <code>structuredClone()</code>. This provides proper deep cloning without the limitations of
JSON serialization.</p>
<h4>Non-compliant code example</h4>
<pre data-diff-id="1" data-diff-type="noncompliant">
const clone = JSON.parse(JSON.stringify(originalObject)); // Noncompliant
</pre>
<h4>Compliant code example</h4>
<pre data-diff-id="1" data-diff-type="compliant">
const clone = structuredClone(originalObject);
</pre>
<h3>Documentation</h3>
<ul>
  <li> <a href="https://github.com/sindresorhus/eslint-plugin-unicorn#readme">eslint-plugin-unicorn</a> - Rule <a
  href="https://github.com/sindresorhus/eslint-plugin-unicorn/blob/HEAD/docs/rules/prefer-structured-clone.md">prefer-structured-clone</a> </li>
  <li> MDN: structuredClone() - <a href="https://developer.mozilla.org/en-US/docs/Web/API/structuredClone">Official documentation for the
  structuredClone() API</a> </li>
  <li> MDN: Structured Clone Algorithm - <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm">Details
  about the structured clone algorithm and supported data types</a> </li>
</ul>
